<?php
header('Content-Type', 'application/x-thrift');
require_once "common.php";

try {
    $transportFactory = new \Thrift\Factory\TTransportFactory();
    $protocolFactory = new \Thrift\Factory\TBinaryProtocolFactory(false,false);
    $transport = new \Thrift\Server\TServerSocket('0.0.0.0', 9090);
    $transport->setAcceptTimeout(100);
    $protocol = new \Thrift\Protocol\TBinaryProtocol($transport, false, false);
    //注册多服务
    $tprocessor = new \Thrift\TMultiplexedProcessor();
    $tprocessor->registerProcessor(
        "ArticleService",
        new \BlogServices\ArticleServiceProcessor(new \Application\Handlers\ArticleHandler())
    );

    $server = new \Thrift\Server\TSimpleServer(
        $tprocessor,
        $transport,
        $transportFactory,
        $transportFactory,
        $protocolFactory,
        $protocolFactory
    );
    $server->serve();
} catch (Exception $exception) {
    print 'TException: ' . $exception->getMessage() . "\n";
}